package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.common.utils.AliOssUtil;
import com.itheima.common.utils.ValidateCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class CommonController {
    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 手机号快速登录发送验证码
     * @param telephone
     * @return
     */
    @GetMapping("/validatecode/send4Login")
    public Result send4Login(String telephone){
        log.info("发送验证码:{}",telephone);

        //生成6位验证码
        Integer sixRandom = ValidateCodeUtils.generateValidateCode(6);

        //将验证码保存到Redis中，并设置有效期5分钟
        redisTemplate.opsForValue().set(telephone,sixRandom,5*60*1000, TimeUnit.SECONDS);
        log.info("保存验证码:{}",sixRandom);

        return Result.success();
    }

}
